﻿using System;
using System.Globalization;

namespace Base.Common.Converters
{
    public class IsNullConverter:ConverterBase
    {
        /// <summary>
        /// 是否反转
        /// </summary>
        public bool Invert { get; set; }

        /// <summary>
        /// 空白字符串是否认为空
        /// </summary>
        public bool WhiteStrIsNull { get; set; } = true;

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string)
            {
                if (WhiteStrIsNull)
                    return string.IsNullOrWhiteSpace(value.ToString()) != Invert;
            }
            return (value == null) != Invert;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
